<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>File: README</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



  <div id="fileHeader">
    <h1>README</h1>
    <table class="header-table">
    <tr class="top-aligned-row">
      <td><strong>Path:</strong></td>
      <td>README
      </td>
    </tr>
    <tr class="top-aligned-row">
      <td><strong>Last Update:</strong></td>
      <td>Thu Feb 04 19:59:19 +0000 2010</td>
    </tr>
    </table>
  </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h2>Welcome to <a href="../classes/Rails.html">Rails</a></h2>
<p>
<a href="../classes/Rails.html">Rails</a> is a web-application framework
that includes everything needed to create database-backed web applications
according to the Model-View-Control pattern.
</p>
<p>
This pattern splits the view (also called the presentation) into
&quot;dumb&quot; templates that are primarily responsible for inserting
pre-built data in between HTML tags. The model contains the
&quot;smart&quot; domain objects (such as Account, Product, Person, Post)
that holds all the business logic and knows how to persist themselves to a
database. The controller handles the incoming requests (such as Save New
Account, Update Product, Show Post) by manipulating the model and directing
data to the view.
</p>
<p>
In <a href="../classes/Rails.html">Rails</a>, the model is handled by
what&#8216;s called an object-relational mapping layer entitled Active
Record. This layer allows you to present the data from database rows as
objects and embellish these data objects with business logic methods. You
can read more about Active Record in <a
href="vendor/rails/activerecord/README.html">files/vendor/rails/activerecord/README.html</a>.
</p>
<p>
The controller and view are handled by the Action Pack, which handles both
layers by its two parts: Action View and Action Controller. These two
layers are bundled in a single package due to their heavy interdependence.
This is unlike the relationship between the Active Record and Action Pack
that is much more separate. Each of these packages can be used
independently outside of <a href="../classes/Rails.html">Rails</a>. You can
read more about Action Pack in <a
href="vendor/rails/actionpack/README.html">files/vendor/rails/actionpack/README.html</a>.
</p>
<h2>Getting Started</h2>
<ol>
<li>At the command prompt, start a new <a
href="../classes/Rails.html">Rails</a> application using the <tt>rails</tt>
command and your application name. Ex: rails myapp

</li>
<li>Change directory into myapp and start the web server:
<tt>script/server</tt> (run with &#8212;help for options)

</li>
<li>Go to <a href="http://localhost:3000">localhost:3000</a>/ and get
&quot;Welcome aboard: You&#8216;re riding the <a
href="../classes/Rails.html">Rails</a>!&quot;

</li>
<li>Follow the guidelines to start developing your application

</li>
</ol>
<h2>Web Servers</h2>
<p>
By default, <a href="../classes/Rails.html">Rails</a> will try to use
Mongrel and lighttpd if they are installed, otherwise <a
href="../classes/Rails.html">Rails</a> will use WEBrick, the webserver that
ships with Ruby. When you run script/server, <a
href="../classes/Rails.html">Rails</a> will check if Mongrel exists, then
lighttpd and finally fall back to WEBrick. This ensures that you can always
get up and running quickly.
</p>
<p>
Mongrel is a Ruby-based webserver with a C component (which requires
compilation) that is suitable for development and deployment of <a
href="../classes/Rails.html">Rails</a> applications. If you have Ruby Gems
installed, getting up and running with mongrel is as easy as: <tt>gem
install mongrel</tt>. More info at: <a
href="http://mongrel.rubyforge.org">mongrel.rubyforge.org</a>
</p>
<p>
If Mongrel is not installed, <a href="../classes/Rails.html">Rails</a> will
look for lighttpd. It&#8216;s considerably faster than Mongrel and WEBrick
and also suited for production use, but requires additional installation
and currently only works well on OS X/Unix (Windows users are encouraged to
start with Mongrel). We recommend version 1.4.11 and higher. You can
download it from <a href="http://www.lighttpd.net">www.lighttpd.net</a>.
</p>
<p>
And finally, if neither Mongrel or lighttpd are installed, <a
href="../classes/Rails.html">Rails</a> will use the built-in Ruby web
server, WEBrick. WEBrick is a small Ruby web server suitable for
development, but not for production.
</p>
<p>
But of course its also possible to run <a
href="../classes/Rails.html">Rails</a> on any platform that supports FCGI.
Apache, LiteSpeed, IIS are just a few. For more information on FCGI, please
visit: <a
href="http://wiki.rubyonrails.com/rails/pages/FastCGI">wiki.rubyonrails.com/rails/pages/FastCGI</a>
</p>
<h2>Apache .htaccess example</h2>
<p>
# General Apache options AddHandler fastcgi-script .fcgi AddHandler
cgi-script .cgi Options +FollowSymLinks +ExecCGI
</p>
<p>
# If you don&#8216;t want <a href="../classes/Rails.html">Rails</a> to look
in certain directories, # use the following rewrite rules so that Apache
won&#8216;t rewrite certain requests # # Example: # RewriteCond
%{REQUEST_URI} ^/notrails.* # RewriteRule .* - [L]
</p>
<p>
# Redirect all requests not available on the filesystem to <a
href="../classes/Rails.html">Rails</a> # By default the cgi dispatcher is
used which is very slow # # For better performance replace the dispatcher
with the fastcgi one # # Example: # RewriteRule ^(.*)$ dispatch.fcgi
[QSA,L] RewriteEngine On
</p>
<p>
# If your <a href="../classes/Rails.html">Rails</a> application is accessed
via an Alias directive, # then you MUST also set the RewriteBase in this
htaccess file. # # Example: # Alias /myrailsapp /path/to/myrailsapp/public
# RewriteBase /myrailsapp
</p>
<p>
RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
</p>
<p>
# In case <a href="../classes/Rails.html">Rails</a> experiences terminal
errors # Instead of displaying this message you can supply a file here
which will be rendered instead # # Example: # ErrorDocument 500 /500.html
</p>
<p>
ErrorDocument 500 &quot;&lt;h2&gt;Application error&lt;/h2&gt;<a
href="../classes/Rails.html">Rails</a> application failed to start
properly&quot;
</p>
<h2>Debugging <a href="../classes/Rails.html">Rails</a></h2>
<p>
Sometimes your application goes wrong. Fortunately there are a lot of tools
that will help you debug it and get it back on the rails.
</p>
<p>
First area to check is the application log files. Have &quot;tail -f&quot;
commands running on the server.log and development.log. <a
href="../classes/Rails.html">Rails</a> will automatically display debugging
and runtime information to these files. Debugging info will also be shown
in the browser on requests from 127.0.0.1.
</p>
<p>
You can also log your own messages directly into the log file from your
code using the Ruby logger class from inside your controllers. Example:
</p>
<pre>
  class WeblogController &lt; ActionController::Base
    def destroy
      @weblog = Weblog.find(params[:id])
      @weblog.destroy
      logger.info(&quot;#{Time.now} Destroyed Weblog ID ##{@weblog.id}!&quot;)
    end
  end
</pre>
<p>
The result will be a message in your log file along the lines of:
</p>
<pre>
  Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
</pre>
<p>
More information on how to use the logger is at <a
href="http://www.ruby-doc.org/core">www.ruby-doc.org/core</a>/
</p>
<p>
Also, Ruby documentation can be found at <a
href="http://www.ruby-lang.org">www.ruby-lang.org</a>/ including:
</p>
<ul>
<li>The Learning Ruby (Pickaxe) Book: <a
href="http://www.ruby-doc.org/docs/ProgrammingRuby">www.ruby-doc.org/docs/ProgrammingRuby</a>/

</li>
<li>Learn to Program: <a
href="http://pine.fm/LearnToProgram">pine.fm/LearnToProgram</a>/ (a
beginners guide)

</li>
</ul>
<p>
These two online (and free) books will bring you up to speed on the Ruby
language and also on programming in general.
</p>
<h2>Debugger</h2>
<p>
Debugger support is available through the debugger command when you start
your Mongrel or Webrick server with &#8212;debugger. This means that you
can break out of execution at any point in the code, investigate and change
the model, AND then resume execution! You need to install ruby-debug to run
the server in debugging mode. With gems, use &#8216;gem install
ruby-debug&#8217; Example:
</p>
<pre>
  class WeblogController &lt; ActionController::Base
    def index
      @posts = Post.find(:all)
      debugger
    end
  end
</pre>
<p>
So the controller will accept the action, run the first line, then present
you with a IRB prompt in the server window. Here you can do things like:
</p>
<pre>
  &gt;&gt; @posts.inspect
  =&gt; &quot;[#&lt;Post:0x14a6be8 @attributes={\&quot;title\&quot;=&gt;nil, \&quot;body\&quot;=&gt;nil, \&quot;id\&quot;=&gt;\&quot;1\&quot;}&gt;,
       #&lt;Post:0x14a6620 @attributes={\&quot;title\&quot;=&gt;\&quot;Rails you know!\&quot;, \&quot;body\&quot;=&gt;\&quot;Only ten..\&quot;, \&quot;id\&quot;=&gt;\&quot;2\&quot;}&gt;]&quot;
  &gt;&gt; @posts.first.title = &quot;hello from a debugger&quot;
  =&gt; &quot;hello from a debugger&quot;
</pre>
<p>
&#8230;and even better is that you can examine how your runtime objects
actually work:
</p>
<pre>
  &gt;&gt; f = @posts.first
  =&gt; #&lt;Post:0x13630c4 @attributes={&quot;title&quot;=&gt;nil, &quot;body&quot;=&gt;nil, &quot;id&quot;=&gt;&quot;1&quot;}&gt;
  &gt;&gt; f.
  Display all 152 possibilities? (y or n)
</pre>
<p>
Finally, when you&#8216;re ready to resume execution, you enter
&quot;cont&quot;
</p>
<h2>Console</h2>
<p>
You can interact with the domain model by starting the console through
<tt>script/console</tt>. Here you&#8216;ll have all parts of the
application configured, just like it is when the application is running.
You can inspect domain models, change values, and save to the database.
Starting the script without arguments will launch it in the development
environment. Passing an argument will specify a different environment, like
<tt>script/console production</tt>.
</p>
<p>
To reload your controllers and models after launching the console run
<tt>reload!</tt>
</p>
<h2>dbconsole</h2>
<p>
You can go to the command line of your database directly through
<tt>script/dbconsole</tt>. You would be connected to the database with the
credentials defined in database.yml. Starting the script without arguments
will connect you to the development database. Passing an argument will
connect you to a different database, like <tt>script/dbconsole
production</tt>. Currently works for mysql, postgresql and sqlite.
</p>
<h2>Description of Contents</h2>
<p>
app
</p>
<pre>
  Holds all the code that's specific to this particular application.
</pre>
<p>
app/controllers
</p>
<pre>
  Holds controllers that should be named like weblogs_controller.rb for
  automated URL mapping. All controllers should descend from ApplicationController
  which itself descends from ActionController::Base.
</pre>
<p>
app/models
</p>
<pre>
  Holds models that should be named like post.rb.
  Most models will descend from ActiveRecord::Base.
</pre>
<p>
app/views
</p>
<pre>
  Holds the template files for the view that should be named like
  weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
  syntax.
</pre>
<p>
app/views/layouts
</p>
<pre>
  Holds the template files for layouts to be used with views. This models the common
  header/footer method of wrapping views. In your views, define a layout using the
  &lt;tt&gt;layout :default&lt;/tt&gt; and create a file named default.html.erb. Inside default.html.erb,
  call &lt;% yield %&gt; to render the view using this layout.
</pre>
<p>
app/helpers
</p>
<pre>
  Holds view helpers that should be named like weblogs_helper.rb. These are generated
  for you automatically when using script/generate for controllers. Helpers can be used to
  wrap functionality for your views into methods.
</pre>
<p>
config
</p>
<pre>
  Configuration files for the Rails environment, the routing map, the database, and other dependencies.
</pre>
<p>
db
</p>
<pre>
  Contains the database schema in schema.rb.  db/migrate contains all
  the sequence of Migrations for your schema.
</pre>
<p>
doc
</p>
<pre>
  This directory is where your application documentation will be stored when generated
  using &lt;tt&gt;rake doc:app&lt;/tt&gt;
</pre>
<p>
lib
</p>
<pre>
  Application specific libraries. Basically, any kind of custom code that doesn't
  belong under controllers, models, or helpers. This directory is in the load path.
</pre>
<p>
public
</p>
<pre>
  The directory available for the web server. Contains subdirectories for images, stylesheets,
  and javascripts. Also contains the dispatchers and the default HTML files. This should be
  set as the DOCUMENT_ROOT of your web server.
</pre>
<p>
script
</p>
<pre>
  Helper scripts for automation and generation.
</pre>
<p>
test
</p>
<pre>
  Unit and functional tests along with fixtures. When using the script/generate scripts, template
  test files will be generated for you and placed in this directory.
</pre>
<p>
vendor
</p>
<pre>
  External libraries that the application depends on. Also includes the plugins subdirectory.
  If the app has frozen rails, those gems also go here, under vendor/rails/.
  This directory is in the load path.
</pre>

    </div>


   </div>


  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>